<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <h1>node操作mongodb</h1>
    <div>
      <div>用户名：<input id="username"/></div>
      <div>密码：<input id="password" type="number"/></div>
      <div>年龄：<input id="age" type="number"/></div>
      <div><button id="register">注册</button></div>
    </div>
    <hr>
    <div>
      <button id="updata">更新</button>
      <button id="del">删除</button>
    </div>

    <script>
      const username = document.querySelector('#username')
      const password = document.querySelector('#password')
      const age = document.querySelector('#age')
      const updata = document.querySelector('#updata')
      const del = document.querySelector('#del')

      del.onclick = () => {
        console.log(111)
        fetch('/api/user/del/66606f6b480582d698e15ce9')
        .then(res => res.json())
        .then(res => {
          console.log(res)
        })
      }

      updata.onclick = () => {
        fetch('/api/user/update/66606f6b480582d698e15ce9',{
          method:"POST",
          body:JSON.stringify({
            username:'章鱼',
            password: '123456',
            age:1
          }),
          headers: {
            "Content-Type":"application/json"
          }
        }).then(res => res.json())
          .then((res) => {
            console.log(res,'update')
          })
      }



      register.onclick = () => {
        fetch('/api/user/add',{
          method: "POST",
          body:JSON.stringify({
            username:username.value,
            password:password.value,
            age:age.value
          }) ,
          headers: {
            "Content-Type":'application/json'
          }
        }).then(res=>res.json()).then(res => {
          console.log(res)
        })
      }
    </script>
  </body>
</html>
